fix(toolkit-lib): downstream stack selection uses wrong key for nested stacks - #1835
Merged
aws-cdk-automation merged 1 commit intoAug 19, 2026
Conversation
Adityaj0
requested a deployment
to
integ-approval
August 14, 2026 21:30 — with
GitHub Actions
Waiting
aws-cdk-automation
enabled auto-merge
August 14, 2026 21:30
mrgrain
approved these changes
Aug 18, 2026
…d stacks includeDownstreamStacks looked up dependencies with `selectedStacks.has(dep.id)`, but selectedStacks/allStacks are keyed by hierarchicalId (manifest.displayName ?? id) everywhere else in this file. For a stack whose displayName differs from its raw id - i.e. stacks inside nested assemblies/stages - this lookup never matches, so a stack that depends on a selected stack is silently dropped from a DOWNSTREAM-expanded selection (the default behavior for `cdk deploy`/`cdk destroy` without `--exclusively`). The symmetric includeUpstreamStacks already does this correctly via `x.manifest.displayName ?? x.id`. This switches includeDownstreamStacks to use the existing `dep.hierarchicalId` getter instead, matching that pattern. Fixes aws#1834
mrgrain
force-pushed
the
fix/downstream-stack-selection-hierarchical-id
branch
from
August 19, 2026 10:45
0ded0db to
93f0230
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1835 +/- ##
=======================================
Coverage 90.92% 90.92%
=======================================
Files 80 80
Lines 12226 12226
Branches 1750 1750
=======================================
Hits 11117 11117
Misses 1073 1073
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #1834
Reason for this change
`includeDownstreamStacks` (`packages/@aws-cdk/toolkit-lib/lib/api/cloud-assembly/stack-assembly.ts`) computes the transitive closure of stacks that depend on the selected set — this is what powers `expand: ExpandStackSelection.DOWNSTREAM`, the default expansion behavior for `cdk deploy`/`cdk destroy` when `--exclusively` is not passed.
`selectedStacks`/`allStacks` are both keyed by `hierarchicalId` (`manifest.displayName ?? id`) — see `indexByHierarchicalId` and `extendStacks` just above, which build these maps via `stack.hierarchicalId`. But the lookup here checks the dependency's raw `.id`, not its `.hierarchicalId`. For a stack whose `displayName` differs from its `id` (stacks inside nested assemblies/stages, e.g. CDK Pipelines), this lookup never matches, so a stack that genuinely depends on a selected stack is silently dropped from the expanded selection.
This was masked for ordinary flat apps, where `displayName` is unset and `id === hierarchicalId`.
The symmetric `includeUpstreamStacks` a few lines below already does this correctly:
Description of changes
Switches `dep.id` to `dep.hierarchicalId` (the existing getter on `CloudArtifact`, equivalent to `includeUpstreamStacks`'s inline `manifest.displayName ?? id` expression) in `includeDownstreamStacks`.
Description of how you validated changes
Added `test/api/cloud-assembly/stack-selection-expand.test.ts` with two regression tests, using `Toolkit.list()` end-to-end through a `TestCloudAssemblySource` fixture: a dependency stack with an explicit `displayName` distinct from its `stackName`/id, and a second stack that depends on it.
Ran the full `test/api/cloud-assembly/`, `test/actions/list.test.ts`, and the rest of `test/actions/` (deploy, diff, synth, drift, rollback, hotswap) — all pass except `bootstrap.test.ts`, which fails identically with or without this change due to a missing `bootstrap-template.yaml` asset that's only copied by a full `yarn build`, not a bare `tsc --build` compile — unrelated to this change.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license